/*
 * @Author: 0x9DEFA478
 * @Date: 2022-01-22 23:06:05
 * @LastEditTime: 2022-07-26 17:05:28
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * QQ:2652450237
 * ============================================================================================================================================
 * 
 * 
 * 
 *                                                                                               ************      ****************************
 *                                                                                             ************      ****************************  
 *                                                                                           ************      ****************************    
 *                                                                                         ************      ****************************      
 *                                                                                       ************      ************                        
 *                                                                                     ************      ************                          
 *                                                                                   ************      ************                            
 *                                                                                 ************      ************                              
 *                                                                               ************      ************                                
 *                                                                             ************      ************                                  
 *                                                                           ************      ************                                    
 *                                                                         ************      ************                                      
 *                                                                       ************      ************                                        
 *                                                                     ************      ************                                          
 *                                                                   ************      ************                                            
 *                                                                 ************      ************                                              
 *                                                               ************      ************                                                
 *                                                             ************      ************                                                  
 *                                                           ************      ************                                                    
 *                                                         ************      ************                                                      
 *                                                       ************      ************                                                        
 *                                                     ************      ************                                                          
 *                                                   ************      ************                                                            
 *                                                 ************      ************                                                              
 *                                               ************      ************                                                                
 *                                             ************      ************                                                                  
 *                                           ************      ************                                                                    
 *                                         ************      ************                                                                      
 *                                       ************      ************                                                                        
 *                                     ************      ************                                                                          
 *                                   ************      ************                                                                            
 *                                 ************      ************                                                                              
 *                               ************      ************                                                                                
 *                             ************      ************                                                                                  
 *                           ************      ************                                                                                    
 *                         ************      ************                                                                                      
 *       ****************************      ************                                                                                        
 *     ****************************      ************                                                                                          
 *   ****************************      ************                                                                                            
 * ****************************      ************                                                                                              
 * 
 * 
 * 
 * ============================================================================================================================================
 * 
 */
#ifndef __Console_H_NES_PPU_H_
#define __Console_H_NES_PPU_H_
#include "../H_NES.h"




#define vH_NES_PPU_Register_PPUCTRL                              0
#define vH_NES_PPU_Register_PPUMASK                              1
#define vH_NES_PPU_Register_PPUSTATUS                            2
#define vH_NES_PPU_Register_OAMADDR                              3

#define vH_NES_PPU_PPUCTRL_I                                     0x04U   //0:PPUADDR自增1  1:PPUADDR自增32
#define vH_NES_PPU_PPUCTRL_S                                     0x08U   //8x8模式下的模式表地址 0:0x0000  1:0x1000
#define vH_NES_PPU_PPUCTRL_B                                     0x10U   //背景模式表地址 0:0x0000  1:0x1000
#define vH_NES_PPU_PPUCTRL_H                                     0x20U   //0:8x8  1:8x16
#define vH_NES_PPU_PPUCTRL_P                                     0x40U   //主从选择 默认为0
#define vH_NES_PPU_PPUCTRL_V                                     0x80U   //NMI使能

#define vH_NES_PPU_PPUMASK_Gray                                  0x01U
#define vH_NES_PPU_PPUMASK_m                                     0x02U   //最左边8列是否显示背景 1:显示
#define vH_NES_PPU_PPUMASK_M                                     0x04U   //最左边8列是否显示精灵 1:显示
#define vH_NES_PPU_PPUMASK_b                                     0x08U   //1:显示背景
#define vH_NES_PPU_PPUMASK_s                                     0x10U   //1:显示精灵
#define vH_NES_PPU_PPUMASK_ER                                    0x20U
#define vH_NES_PPU_PPUMASK_EG                                    0x40U
#define vH_NES_PPU_PPUMASK_EB                                    0x80U

#define vH_NES_PPU_PPUSTATUS_O                                   0x20U   //精灵溢出
#define vH_NES_PPU_PPUSTATUS_S                                   0x40U   //Sprite 0 Hit
#define vH_NES_PPU_PPUSTATUS_V                                   0x80U   //指示是否在Vblank  1:处在Vblank




typedef struct{
  Huint32 PatternToLineBuffer[256];//Pattern转行背景缓存表 76543210 ---> xxx0xxx1xxx2xxx3xxx4xxx5xxx6xxx7
  Hbyte ReverseBitTable[256];//位反转表
}H_NES_PPU_Table;

typedef struct{

  Huint32 Buffer[8];
  Huint32 BufferValid[8];
  Hbyte Priority;
  Hbyte ExistSprite0;
  Hbyte OAM_Count;

}H_NES_PPU_SubOAMInfo;

typedef struct{

  Hbyte* NameTable[4];

  struct{
    Hbyte Register[4];

    struct{
      Huint16 v;
      Huint16 t;
      Hbyte x;
      Hbyte w;

      int IsAddXY;
    }Internal;

    struct{
      Hbyte ReadBuffer;
    }PPUDATA;
  }Register;

  struct{
    int IsOddFrame;

    Huint32 LineBuffer[33];//行背景缓存
    
    H_NES_PPU_SubOAMInfo* SubOAMInfo;//存放扫描线中每8个像素的OAM信息
    
  }Renderer;

  Hbyte Palettes[32];//调色板
  Hbyte OAM[256];
  Hbyte* LineBuffer_Output;//行缓存 输出

  H_NES_PPU_Table* Table;//一些转换表


  void* VRAM;
  Hbyte VRAM_ScreenType;//0x00:单屏 0x01:垂直排列 0x02:水平排列 0x03:四屏

}H_NES_PPU;




#endif //__Console_H_NES_PPU_H_
